package com.ruoyi.web.controller.combat.apprisk;

import cn.hutool.core.date.DateUtil;
import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.redis.RedisCache;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/api/check")
public class CombatPhoneLoginController  extends BaseController {

    @Autowired
    private RedisCache redisCache;


    @GetMapping("/loginStates")
    public AjaxResult loginStates(){

        try {
            String key = Constants.LOGIN_PHONE_KEY + getUserId();
            Map cacheObject = redisCache.getCacheObject(key);
            if (cacheObject != null) {
                cacheObject.put("token", getLoginUser().getToken());
                cacheObject.put("date", new Date().getTime());
                cacheObject.put("userId", getUserId());
                cacheObject.put("phoneNum", getLoginUser().getUser().getPhonenumber());
            }else{
                cacheObject = new HashMap();
                cacheObject.put("token", getLoginUser().getToken());
                cacheObject.put("date", new Date().getTime());
                cacheObject.put("userId", getUserId());
                cacheObject.put("phoneNum", getLoginUser().getUser().getPhonenumber());
            }
            redisCache.setCacheObject(key, cacheObject);
        } catch (Exception e) {
            return AjaxResult.error();
        }
        return AjaxResult.success();
    }





}
